package com.yjz.demo.tab

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.yjz.common.tab.FragmentTabView
import com.yjz.common.tab.TabViewAdapter
import com.yjz.demo.R
import com.yjz.ui.tab.common.TabInfo
import com.yjz.ui.tab.top.TabTopLayout

/**
 *作用 : tabLayout演示
 *作者 : yjz
 *时间 : 2024/9/18 15:59
 */
public class TopTabLayoutActivity : AppCompatActivity() {

    var tabsStr: Array<String> = arrayOf(
        "热门",
        "服装",
        "数码",
        "鞋子",
        "零食",
        "家电",
        "汽车",
        "百货",
        "家居",
        "装修",
        "运动"
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_top_tab_layout)
        val hiTabTopLayout: TabTopLayout = findViewById(R.id.tab_layout)
        val infoList: MutableList<TabInfo<*>> = ArrayList()
        for (s in tabsStr) {
            val info: TabInfo<String> = TabInfo<String>(s, "#ff0000", "#000000")
            info.fragment = NormalFragment.newInstance(s)
            infoList.add(info)
        }
        hiTabTopLayout.inflateInfo(infoList)

        val fragmentTabView = findViewById<FragmentTabView>(R.id.fragment_tab_view)
        val adapter = TabViewAdapter(infoList, supportFragmentManager);
        fragmentTabView.adapter = adapter

        hiTabTopLayout.addTabSelectChangeListener { index, _, _ ->
            fragmentTabView.setCurrentItem(index);
        }
        hiTabTopLayout.defaultSelected(infoList[0])
    }
}